package org.zoomdev.zoom.aop.impl;

import org.zoomdev.zoom.aop.AopFactory;
import org.zoomdev.zoom.aop.AspectFactory;
import org.zoomdev.zoom.aop.Interceptor;
import org.zoomdev.zoom.common.filter.MethodFilter;
import org.zoomdev.zoom.ioc.Ioc;

public final class AspectFactoryImpl implements AspectFactory {
    private final AopFactory aopFactory;
    private final Ioc ioc;

    public AspectFactoryImpl(AopFactory aopFactory, Ioc ioc) {
        this.ioc = ioc;
        this.aopFactory = aopFactory;
    }

    public void createAspect(Interceptor interceptor, MethodFilter filter) {
        this.aopFactory.addFactory((targetClass, method, interceptors) -> interceptors.add(interceptor), filter, 0);
    }

    public void createAspect(Interceptor interceptor, String pattern) {
        this.aopFactory.addFactory((targetClass, method, interceptors) -> interceptors.add(interceptor), pattern, 0);
    }
}